package weifei.live.simulation;


// import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
// import weifei.live.simulation.entity.*;
// import weifei.live.simulation.im.entity.*;
import weifei.live.simulation.interceptor.AdminerJWTInterceptor;
import weifei.live.simulation.interceptor.GroupOwnerInterceptor;
import weifei.live.simulation.interceptor.UserJWTInterceptor;
// import weifei.mall.entity.*;


@Configuration
public class WebCofig implements WebMvcConfigurer
{
    /* 跨域
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //是否发送Cookie
                .allowCredentials(true)
                //放行哪些原始域
                .allowedOriginPatterns("*")
                .allowedMethods("*")
                .allowedHeaders("*")
                .exposedHeaders("*");
    }
    */


    @Bean
    public CharacterEncodingFilter characterEncodingFilter(){
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        filter.setForceEncoding(true);
        return filter;
    }


    public void addInterceptors(InterceptorRegistry registry)
    {
        registry
                .addInterceptor(new AdminerJWTInterceptor())
                .addPathPatterns("/db/**")
                .addPathPatterns("/adminer/createGroup")
                .addPathPatterns("/adminer/addTradeArea")
                .addPathPatterns("/adminer/addSort");


        registry
                .addInterceptor(new UserJWTInterceptor())
                .addPathPatterns("/im/**")
                .addPathPatterns("/user/**")
                .addPathPatterns("/group/**")

                .excludePathPatterns("/im/connect/**")
                .excludePathPatterns("/im/live/group/getLiveStreamState")
                .excludePathPatterns("/im/live/group/getAllLiveStreamVideoTimeCache")
                .excludePathPatterns("/im/live/group/getLiveStreamVideoTimeCache")
                .excludePathPatterns("/im/live/group/getLiveStreamVideoURL")

                .excludePathPatterns("/user/register")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/getUserByID")
                .excludePathPatterns("/user/getUserAvatarByUserID")
                .excludePathPatterns("/user/getFollowCountByUserID")
                .excludePathPatterns("/user/getFansCountByUserID")

                .excludePathPatterns("/group/getGroupByID")
                .excludePathPatterns("/group/getGroupListByOwnerID")
                .excludePathPatterns("/group/getGroupAvatarByGroupID")
                .excludePathPatterns("/group/getGroupIDsBySortID")
                .excludePathPatterns("/group/getSorts");

        registry
                .addInterceptor(new GroupOwnerInterceptor())
                .addPathPatterns("/group/disband")
                .addPathPatterns("/group/addGroupToTradeArea")
                .addPathPatterns("/group/addSort")
                .addPathPatterns("/group/deleteSort")
                .addPathPatterns("/im/live/group/openLiveStream")
                .addPathPatterns("/im/live/group/closeLiveStream")
                .addPathPatterns("/im/live/group/addLiveStreamVideoTimeCache");

                // 这个不能搞，它给的 缓存ID
                // .addPathPatterns("/im/live/group/deleteLiveStreamVideoTimeCache");
    }


    @Bean("objectMapper")
    public ObjectMapper objectMapper() { return new ObjectMapper(); }

}

